var domain='m.bingofresh.com';
var daojstt;
//var domain='192.168.0.22';
function setCookie(name,value,e)
{
    var exp = new Date();
    exp.setTime(exp.getTime() + 30*24*60*60*1000);
    if(e===true){
        document.cookie = name + "="+ escape (value) + ";";
    }else{
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";";
    }
}
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}
function delCookie(name)
{

	var exp = new Date();
    exp.setTime(exp.getTime() - 1000);
    var cval=getCookie(name);

    if(cval!=null){
        document.cookie= name + "="+cval+";expires="+exp.toGMTString()+";";
    }
}
function in_buy_car_yugou(pid,title,num,price,jump){
	var buycar=getCookie('buycar_yugou');
	if (buycar!==null && buycar!=''){
		buycar=buycar.split('|');
	}else{
		buycar=new Array();
	}
	var has=false;
	for (var i = 0; i < buycar.length; i++) {
		buycar[i]=buycar[i].split(',');
		if (price==0 ){
			if(buycar[i][3]==0){
				buycar[i][0]=pid;
				buycar[i][1]=title;
				has=true;
			}
		}else{
			if (buycar[i][0]==pid){
				buycar[i][2]=num;
				buycar[i][3]=price;
				has=true;
			}
		}
		buycar[i]=buycar[i].join(',');		
	}
	if (!has){
		buycar.push(pid+','+title+','+num+','+price);
	}
	buycar=buycar.join('|');
	setCookie('buycar_yugou',buycar); 
/*
	$("#fixnav").hide();
	if(jump!=='no'){
		window.location.href='weixinshop-yugou.html';
	}
*/
	//$.mobile.changePage('weixinshop-buycar.html',{'transition':'slide','reloadPage':true});
}


function in_buy_car(pid,title,num,price,jump){
	var buycar=getCookie('buycar');
	if (buycar!==null && buycar!=''){
		buycar=buycar.split('|');
	}else{
		buycar=new Array();
	}
	var has=false;
	for (var i = 0; i < buycar.length; i++) {
		var tmp = buycar[i].split(',');
		//如果存在
		if (tmp[0] == pid) {
			tmp[2] = num;
			tmp[3] = price;
			//wlq 如果数量为0，删除cookeies
			if (num <= 0) {
				buycar.splice(i, 1);
			}else {
				buycar[i]=tmp.join(',');
			}
			has=true;
			break;
		}
	}
	if (!has && num>0){
		buycar.push(pid+','+title+','+num+','+price);
	}
	buycar=buycar.join('|');
	setCookie('buycar',buycar,true);
/*
	$("#fixnav").hide();
	if(jump!=='no'){
		window.location.href='weixinshop-buycar.html';
	}
*/
	//$.mobile.changePage('weixinshop-buycar.html',{'transition':'slide','reloadPage':true});
}

function parsePrice(p){
	p=parseFloat(p);
	if (p==0){
		return 0;
	}else{
		var tmp=parseInt(p);
		if(tmp==p){
			return tmp;
		}else{
			tmp=p.toFixed(1);
			if(tmp==p){
				return tmp;
			}else{
				return p;
			}
		}
	}
}
function daojishi(id,t,serverTime){
         
	this.o=$('#djs');
	var myDate=new Date();
	//var now=myDate.getHours()*3600+myDate.getMinutes()*60+myDate.getSeconds();
    //alert ("t:"+t+",now:"+now);
    var now=serverTime;
	if (t<now){
		t+=86400;
	}
	if (daojstt)
	{
		
		clearTimeout(daojstt);
	}else{
		setTimeout(this.jsq,1000);
	}
	
	this.Times=t-now;
	var self=this;
	this.jsq=function(){
		if (self.Times>=0){
			var D=parseInt(self.Times/86400);
			var H=parseInt((self.Times-D*86400)/3600);
			var i=parseInt((self.Times -D*86400 - H * 3600)/60);
			var s=self.Times-H*3600-i*60-D*86400;
			var html='';
			if (D!=0){
					html="<strong>"+D+"天</strong><strong>"+H+"小时</strong><strong>"+i+"分</strong><strong>"+s+"秒</strong>";
			}else{
				if (H!=0){
					html="<strong>"+H+"小时</strong><strong>"+i+"分</strong><strong>"+s+"秒</strong";
				}else{
					if (i!=0){
						html='<strong>'+i+'分</strong><strong>'+s+'秒</strong>';
					}else{
						html='<strong>'+s+'秒</strong>';
					}
				}
			}
			//self.o.addClass('ui-disabled');
			self.o.html (html);
			//self.o.find('.ui-btn-text').html(html);
			self.Times--;
			daojstt=window.setTimeout(self.jsq,1000);
		}else{
			console.info('location');
			window.location.reload();
		}
	}
	jsq();
	
}
function popout(obj){
	binguoApp.fn.popout(obj);
}